<!-- 订单 -->
<template>
  <div class="order">
    <!-- app 头部 -->
    <AppBar class="app-bar" color="primary" title="订单">
      <Button icon slot="left"  @click="$store.state.userDrawer.open=true">
        <Icon value="menu"></Icon>
      </Button>
    </AppBar>
    <Tabs class="tabs" :value.sync="tabsActive" inverse color="teal" full-width>
      <Tab>我的发布</Tab>
      <Tab>我的申请</Tab>
    </Tabs>
    <!-- 列表 -->
    <LoadMore :loading="loading" @load="load">
      <List ref="scrollWrapper" class="list-wrapper" textline="two-line">
        <div v-for="(item, index) in boxList" :key="index">
          <ListItem @click="showBoxDetail(item, index)" button :ripple="false">
            <ListAction>
              <ListItemContent>
                <ListItemTitle>{{item.title}}</ListItemTitle>
                <ListItemSubTitle>{{item.date}}</ListItemSubTitle>
              </ListItemContent>
            </ListAction>
          </ListItem>
          <Divider></Divider>
        </div>
      </List>
    </LoadMore>
    <!-- 箱子详情 -->
    <box-detail :open="boxDetailOpen" @close="boxDetailClose"></box-detail>
    <!-- 用户抽屉 -->
    <UserDrawer></UserDrawer>
  </div>
</template>

<script lang="ts">
import {Component, Vue} from "vue-property-decorator";
import { Tabs, Tab } from "@/components/Tabs";
import { LoadMore } from "@/components/LoadMore";
import { List, ListAction, ListItem, ListItemContent, ListItemTitle, ListItemSubTitle } from "@/components/List";
import Divider from "@/components/Divider";
import AppBar from "@/components/AppBar";
import Button from "@/components/Button";
import Icon from "@/components/Icon";
import UserDrawer from "@/views/common/user-drawer.vue";
import BoxDetail from "@/views/common/box-detail.vue";

@Component({
  components: {
    Tabs,
    Tab,
    List,
    ListItem,
    ListAction,
    ListItemContent,
    ListItemTitle,
    ListItemSubTitle,
    Divider,
    AppBar,
    Button,
    Icon,
    UserDrawer,
    BoxDetail,
    LoadMore
  }
})
export default class Order extends Vue {

  tabsActive = 0;
  boxList = [
    { title: "标题", date: "Jan 9, 2014" },
    { title: "标题", date: "Jan 9, 2014" },
    { title: "标题", date: "Jan 9, 2014" },
    { title: "标题", date: "Jan 9, 2014" },
    { title: "标题", date: "Jan 9, 2014" },
    { title: "标题", date: "Jan 9, 2014" },
    { title: "标题", date: "Jan 9, 2014" },
    { title: "标题", date: "Jan 9, 2014" }
  ];
  boxDetailOpen = false;
  loading = false;

  load () {
    this.loading = true;
    setTimeout(() => {
      this.loading = false;
      const newArr = [
        { title: "标题", date: "Jan 9, 2014" },
        { title: "标题", date: "Jan 9, 2014" },
        { title: "标题", date: "Jan 9, 2014" },
        { title: "标题", date: "Jan 9, 2014" }
      ];
      newArr.map((item) => {
        this.boxList.push(item);
      });
      this.num += 10;
    }, 1500);
  }

  showBoxDetail (item, index) {
    this.boxDetailOpen = true;
  }

  boxDetailClose () {
    this.boxDetailOpen = false;
  }

  mounted () {
    const mainLayout = document.getElementById("mainLayout");

    window.onscroll = () => {
      let st = mainLayout.scrollTop;
      let sh = mainLayout.scrollHeight;
      let oh = mainLayout.offsetHeight;
      console.log(st);
      if (Math.ceil(st) + oh >= sh) {

      }
    }

  }

}
</script>

<style lang="less">
  .order{
    position: relative;
    overflow: hidden;
    .tabs{
      position: fixed;
      top: 56px;
      z-index: 1;
      width: 100%;
    }
    .list-wrapper{
      margin-top: 48px;
    }
  }
</style>
